package com.mcflies.commons;

import java.util.List;
import java.util.Map;

import com.mcflies.ui.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author:mcfly_jun
 * @create_date:2012-8-10
 * @comment:/src/com/mcflies/ui/menu/MenuMainActivity.java中的GridView自定义适配器
 */
public class MenuMainAdapter extends BaseAdapter {
	private Context context;
	private List<Map<String, Object>> menuDataList;

	public MenuMainAdapter() {
	}

	public MenuMainAdapter(Context context,
			List<Map<String, Object>> menuDataList) {
		this.context = context;
		this.menuDataList = menuDataList;
	}

	@Override
	public int getCount() {
		return menuDataList.size();
	}

	@Override
	public Object getItem(int position) {
		return menuDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		view = LayoutInflater.from(context).inflate(R.layout.menu_main_item,
				null);// 用LayoutInflater装载布局。
		Map<String, Object> menuDataMap = menuDataList.get(position);
		ImageView menuImage_IV = (ImageView) view
				.findViewById(R.id.menuMainItemImage);

		Bitmap menuMainImage = (Bitmap) menuDataMap
				.get(McfliesConstant.MenuMainConstant.MENU_MAIN_IMAGE);
		menuImage_IV.setImageBitmap(menuMainImage);

		TextView menuDes_Tv = (TextView) view
				.findViewById(R.id.menuMainItemDes);
		String menuMainDes = (String) menuDataMap
				.get(McfliesConstant.MenuMainConstant.MENU_MAIN_DES);

		menuDes_Tv.setText(menuMainDes);
		return view;
	}
}
